package com.yong;

import com.yong.mapper.AcademyMapper;
import com.yong.pojo.Academy;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * @author PureYY
 */
public class MybatisDemo {

    public static void main(String[] args) throws IOException {


        //    加载核心mybatis配置文件 获取SqlSessionFactory
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        //2. 获取SqlSession对象，用它来执行sql
        SqlSession sqlSession = sqlSessionFactory.openSession();

        //3.1 获取UserMapper接口的代理对象
        AcademyMapper userMapper = sqlSession.getMapper(AcademyMapper.class);
        List<Academy> users = userMapper.selectAll();

        System.out.println(users);

    }
}

